package com.gree.scmservice.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.threadnew.tnmq.common.ConsumerMessageListener;
import com.threadnew.tnmq.common.ConsumerStatus;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * Created by 180686 on 2021/6/23 14:46
 */
@Component
public class SaasConsumer implements ConsumerMessageListener {

    @Autowired
    private MultiRouteDataSource dynamicDataSource;

    @Override
    public ConsumerStatus handle(Object o, MessageExt messageExt) throws Exception {
        try {
            HashMap<String,Object> map = (HashMap<String, Object>) o;
            String clientid = map.get("clientid")==null?"":map.get("clientid").toString();
            String password = map.get("password")==null?"":map.get("password").toString();
            DruidDataSource druidDataSource = new DruidDataSource();
            druidDataSource.setUrl("jdbc:oracle:thin:@10.2.25.123/ggrdattest");
            druidDataSource.setUsername(clientid);
            druidDataSource.setPassword(password);
            dynamicDataSource.addDataSource(druidDataSource);
        } catch (Exception e) {
            return ConsumerStatus.FAIL;
        }
        return ConsumerStatus.OK;
    }
}
